package com.yimi.yinhepda.views.main.my_module;


import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.pda.ym.utils.SharedPreferUtil;
import com.uce.pda.bleblue.CrBtScanActivity;
import com.uce.pda.downexample.ui.menu.MenuActivity;
import com.uce.pda.watcher.SwitchButton;
import com.yimi.yinhepda.R;
import com.pda.ym.utils.AppInfoHelper;
import com.yimi.yinhepda.base.BaseInitActivity;
import com.yimi.yinhepda.views.setting_module.PdaInfoActivity;
import com.yimi.yinhepda.views.setting_module.ServerSettingActivity;

import butterknife.Bind;
import butterknife.OnClick;

import static com.uce.pda.view.SwitchButton.*;

/**
 * @author: lj
 * Date: 2019/9/20 16:03
 * Description: 本机设置
 */
public class LocalSettingActivity extends BaseInitActivity {

    @Bind(R.id.iv_back)
    ImageView ivBack;
    @Bind(R.id.tv_title)
    TextView tvTitle;
    @Bind(R.id.tv_version_name)
    TextView tvVersionName;
    @Bind(R.id.switch_btn)
    SwitchButton switchBtn;

    @Override
    public String getPageName() {
        return "本机设置";
    }

    @Override
    public int getContentViewId() {
        return R.layout.activity_local_setting;
    }

    @Override
    public void initView(Bundle savedInstanceState) {

    }

    @Override
    public void initEvent() {

    }

    @Override
    public void initData() {
        ivBack.setVisibility(View.VISIBLE);
        tvTitle.setText(getPageName());
        tvVersionName.setText(String.format("版本号：%s", AppInfoHelper.getAppVersionName(this)));
        String switchState=sharedPreferUtil.getValue(SharedPreferUtil.KUAIDI_MERGE_LOAD_SWITCH);
        if ("1".equals(switchState)){
            switchBtn.setChecked(true);
        }
        else if("0".equals(switchState)){
            switchBtn.setChecked(false);
        }

        switchBtn.setOnCheckedChangeListener(new SwitchButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(SwitchButton view, boolean isChecked) {
                if (isChecked){
                    SharedPreferUtil.getInstance().setValue(SharedPreferUtil.KUAIDI_MERGE_LOAD_SWITCH,"1");
                }
                else{
                    SharedPreferUtil.getInstance().setValue(SharedPreferUtil.KUAIDI_MERGE_LOAD_SWITCH,"0");
                }
            }
        });
    }

    @OnClick({R.id.iv_back,R.id.ll_wifi_setting, R.id.ll_bluetooth_setting, R.id.ll_server_setting,
            R.id.ll_local_info, R.id.ll_specific_setting,R.id.ll_jipaoji_setting,R.id.ll_zhihuan_setting,R.id.ll_orgin_switch_setting})
    @Override
    protected void onClickBtn(View v) {
        super.onClickBtn(v);
        switch (v.getId()) {
            case R.id.iv_back:
                finish();
                break;
            case R.id.ll_wifi_setting:
                //WiFi设置
                Intent intent = new Intent(android.provider.Settings.ACTION_WIFI_SETTINGS);
                startActivity(intent);
                break;
            case R.id.ll_bluetooth_setting:
                //蓝牙设置
                Intent wifiIntent = new Intent(this,BlueToothActivity.class);
                startActivity(wifiIntent);
                break;
            case R.id.ll_server_setting:
                //服务设置
                toActivity(ServerSettingActivity.class);
                break;
            case R.id.ll_local_info:
                //本机信息
                toActivity(PdaInfoActivity.class);
                break;
            case R.id.ll_specific_setting:
                //个性设置
                toActivity(SpecificActivity.class);
                break;
            case R.id.ll_zhihuan_setting:
                //指环设置
                Intent zhiHuanIntent = new Intent(this, CrBtScanActivity.class);
                startActivity(zhiHuanIntent);
                break;
            case R.id.ll_jipaoji_setting:
                //计泡机设置
                Intent jipaojiIntent = new Intent(this, MenuActivity.class);
                startActivity(jipaojiIntent);
                break;
            case R.id.ll_orgin_switch_setting:
                Intent orginIntent = new Intent(this, MenuActivity.class);
                startActivity(orginIntent);
                break;
            default:
                break;
        }
    }

}
